import { get2s } from './com'
export class MyDateUtils {
  static ymd() {
    const date = new Date()
    return `${date.getFullYear()}-${get2s(date.getMonth() + 1)}-${get2s(date.getDate())}`
  }
  static ym() {
    const date = new Date()
    return `${date.getFullYear()}-${get2s(date.getMonth() + 1)}`
  }
  static ymdHm() {
    const date = new Date()
    return `${date.getFullYear()}-${get2s(date.getMonth() + 1)}-${get2s(date.getDate())} ${get2s(date.getHours())}:${get2s(date.getMinutes())}`
  }
  static ymdHms() {
    const date = new Date()
    return `${date.getFullYear()}-${get2s(date.getMonth() + 1)}-${get2s(date.getDate())} ${get2s(date.getHours())}:${get2s(date.getMinutes())}:${get2s(date.getSeconds())}`
  }
}
//
export class DateTimeUtils {
  /**
   * 获取某月的天数
   *
   * @param year  年
   * @param month 月
   * @returns 某月的天数
   */
  static getMonthDayCount(year: number, month: number) {
    let count = 0
    // 判断大月份
    if (
      month == 1 ||
      month == 3 ||
      month == 5 ||
      month == 7 ||
      month == 8 ||
      month == 10 ||
      month == 12
    ) {
      count = 31
    }
    // 判断小月
    if (month == 4 || month == 6 || month == 9 || month == 11) {
      count = 30
    }
    // 判断平年与闰年
    if (month == 2) {
      if (this.isLeapYear(year)) {
        count = 29
      } else {
        count = 28
      }
    }
    return count
  }
  /**
   * 是否是闰年
   *
   * @param year year
   * @returns 是否是闰年
   */
  static isLeapYear(year: number) {
    return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0
  }
}
